package com.bole.controller;


import com.bole.data.Result;
import com.bole.data.ResultEnum;
import com.bole.dto.content.DicContentTypeDto;
import com.bole.dto.content.TbContentDto;
import com.bole.feign.ContentFeign;
import com.bole.feign.ContentTypeFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("content")
@Api(value = "广告管理接口")
public class ContentController {

    @Autowired
    private ContentFeign contentFeign;

    @Autowired
    private ContentTypeFeign contentTypeFeign;

    @GetMapping("tolist")
    @ApiOperation(value = "跳转广告页面",notes = "没啥好注释的")
    public String tolist(Model model){
        List<DicContentTypeDto> list = contentTypeFeign.getContentInfo();
        model.addAttribute("list",list);
        return "/content/content-list";
    }

    @GetMapping("getContentInfo")
    @ResponseBody
    @ApiOperation(value = "查询全部广告",notes = "查询全部广告")
    public Result getContentInfo() {
        List<TbContentDto> contentInfo = contentFeign.getContentInfo();
        return Result.response(ResultEnum.OK).setData(contentInfo);
    }

    @PostMapping("addContentInfo")
    @ResponseBody
    @ApiOperation(value = "增加广告",notes = "增加广告")
    @ApiImplicitParam(name = "content",value = "广告实体类",required = true,paramType = "body",dataTypeClass = TbContentDto.class)
    public Result addContentInfo(@RequestBody TbContentDto content) {
       contentFeign.addContentInfo(content);
        return Result.response(ResultEnum.OK);
    }

    @PostMapping("toUpdate/{id}")
    @ResponseBody
    @ApiOperation(value = "修改回显查询",notes = "修改回显查询")
    @ApiImplicitParam(name = "id",value = "广告id",required = true,dataTypeClass = Long.class)
    public Result toUpdate(@PathVariable("id") Long id) {
        TbContentDto tbContentDto = contentFeign.toUpdate(id);
        return Result.response(ResultEnum.OK).setData(tbContentDto);
    }


    @PostMapping("updateById")
    @ResponseBody
    @ApiOperation(value = "修改广告",notes = "修改广告")
    @ApiImplicitParam(name = "content",value = "广告实体类",required = true,paramType = "body",dataTypeClass = TbContentDto.class)
    public Result updateById(@RequestBody TbContentDto content) {
        contentFeign.updateById(content);
        return Result.response(ResultEnum.OK);
    }

    @PostMapping("deleteBatch")
    @ResponseBody
    @ApiOperation(value = "删除广告",notes = "删除广告")
    @ApiImplicitParam(name = "idss",value = "广告id集",required = true,dataTypeClass = Long.class)
    public Result deleteBatch(@RequestParam("idss") List<Long> idss) {
        contentFeign.deleteBatch(idss);
        return Result.response(ResultEnum.OK);
    }

    @GetMapping("getContentInfoByCate/{id}")
    @ResponseBody
    @ApiOperation(value = "根据广告类型查询",notes = "根据广告类型查询")
    @ApiImplicitParam(name = "id",value = "广告分类id",required = true,paramType = "path",dataTypeClass = Long.class)
    public Result getContentInfoByCate(@PathVariable("id") Long id) {
        List<TbContentDto> contentInfoByCate = contentFeign.getContentInfoByCate(id);
        return Result.response(ResultEnum.OK).setData(contentInfoByCate);
    }


}
